<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="库存日志" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link href="/css/Query.css" rel="stylesheet" type="text/css">
<link href="/calendar/dhtmlgoodies_calendar/dhtmlgoodies_calendar.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="/css/BillList.css" />
<script src="/js/QueryList.js"></script>

<script src="/js/popup_ext.js"></script>
<script src="/calendar/dhtmlgoodies_calendar/dhtmlgoodies_calendar.js"></script>
<script language="javascript">
	function doShow(billId,billType){
		var url;
		if(billType=='IN_BILL'){
			url="/storehouse/InBillEdit.ihtm?id="+billId;
		}else if(billType=='OUT_BILL'){
			url="/storehouse/OutBillEdit.ihtm?id="+billId;
		}else if(billType=="ALLO_BILL"){
			url="/storehouse/AlloBillEdit.ihtm?id="+billId;
		}else if(billType=="PURC_BILL"){
			url="/purchase/PurchaseBillEdit.ihtm?id="+billId;
		}else{
			return;
		}
		ShowIframe("查看",url,1024,500,"",1024,600);
	}
	function doCancel(){
		window.close();
	}
	function doInit(){
		Window_Onload();
		if(window.screen.availWidth>1024){
			var w=window.screen.availWidth*0.98;
			window.resizeTo(w,600);
			//居中
			var resizeWinTop=(window.screen.availHeight-600)/2;
			var resizeWinLeft=(window.screen.availWidth-w)/2;
			window.moveTo(resizeWinLeft,resizeWinTop);
		}
	}
	function checkDateStr(){
		var startDate=document.getElementById("start_date").value;
		if(startDate==null || startDate==''){
			ShowAlert('提示框','请选择开始日期',200,100);
			return false;
		}else{
			var arr=startDate.split("-");
			if(arr.length==null || arr.length!=3){
				ShowAlert('提示框','开始日期格式不正确',200,100);
				return false;
			}else if(isNaN(arr[0]) || isNaN(arr[1]) || isNaN(arr[2])){
				ShowAlert('提示框','开始日期格式不正确',200,100);
				return false;
			}
		}
		var endDate=document.getElementById("end_date").value;
		if(endDate==null || endDate==''){
			ShowAlert('提示框','请选择结束日期',200,100);
			return false;
		}else{
			var arr=endDate.split("-");
			if(arr.length==null || arr.length!=3){
				ShowAlert('提示框','结束日期格式不正确',200,100);
				return false;
			}else if(isNaN(arr[0]) || isNaN(arr[1]) || isNaN(arr[2])){
				ShowAlert('提示框','结束日期格式不正确',200,100);
				return false;
			}
		}
		return true;
	}
	function createPageParaStr(){
		var str="start_date="+encodeURIComponent(document.getElementById("start_date").value);
		str=str+"&end_date="+encodeURIComponent(document.getElementById("end_date").value);
		str=str+"&sto_id="+document.getElementById("sto_id").value;
		str=str+"&pro_id="+document.getElementById("pro_id").value;
		str=str+"&pro_name="+encodeURIComponent(document.getElementById("pro_name").value);
		str=str+"&pro_code="+encodeURIComponent(document.getElementById("pro_code").value);
		
		return str;
	}
	
	function createProgramParaStr(){
		var str="start_date="+encodeURIComponent(document.getElementById("hid_start_date").value);
		str=str+"&end_date="+encodeURIComponent(document.getElementById("hid_end_date").value);
		str=str+"&sto_id=${stoId}";
		str=str+"&pro_id=${proId}";
		str=str+"&pro_name="+encodeURIComponent(document.getElementById("hid_pro_name").value);
		str=str+"&pro_code="+encodeURIComponent(document.getElementById("hid_pro_code").value);
		
		return str;
	}
	function doSearch(){
		var stoId=document.getElementById("sto_id").value;
		if(stoId==null || stoId=='' || stoId=='0'){
			ShowAlert('提示框','请选择仓库',200,100);
			return;
		}
		
		var str;
		if(IsAdvSearch){//高级
			str="search_type=1";
			if(document.getElementById("cb_order_date").checked){
				if(checkDateStr()){
					str=str+"&cb_order_date=1";
				}else{
					return;
				}
			}
			if(document.getElementById("cb_pro_name").checked){
				var proId=document.getElementById("pro_id").value;
				if(proId==null || proId=='' || proId=='0'){
					ShowAlert('提示框','请选择品名规格',200,100);
					return;
				}
				str=str+"&cb_pro_name=1";
			}
			if(document.getElementById("cb_pro_code").checked){
				var proCode=document.getElementById("pro_code").value.trim();
				if(proCode==null || proCode==""){
					ShowAlert('提示框','请输入材料编号',200,100);
					return;
				}
				str=str+"&cb_pro_code=1";
			}
		}else{//快速
			str="search_type=2";
			if(!checkDateStr()){
				return;
			}
		}
		var paraStr=createPageParaStr();
		if(paraStr!=""){
			str=str+"&"+paraStr;
		}
		
		document.getElementById("contentDiv").style.display="none";
		document.getElementById("waitDiv").style.display="";
		window.location="/storehouse/InOutLogList.ihtm?"+str;
	}
	function getSearchCondition(){
		var searchType="${searchType}";
		var str="search_type="+searchType;
		if(searchType=="1"){//高级
			<c:if test="${cbOrderDate=='1'}">str=str+"&cb_order_date=1";</c:if>
			<c:if test="${cbProName=='1'}">str=str+"&cb_pro_name=1";</c:if>
			<c:if test="${cbProCode=='1'}">str=str+"&cb_pro_code=1";</c:if>
		}else{//快速
			
		}
		var paraStr=createProgramParaStr();
		if(paraStr!=""){
			str=str+"&"+paraStr;
		}
		return str;
	}
	function checkInput(){
		if(window.event.keyCode==13){
			doSearch();
		}
	}
	function doAutoCheck(objId){
		document.getElementById(objId).checked=true;
	}
	function setDate(type){
		var d=new Date();
		var startStr="";
		var endStr="";
		if(type=="CURRENT_MONTH"){
			startStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-01";
			endStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}else if(type=="PREVIEW_MONTH"){
			d=new Date(d.getFullYear(),d.getMonth(),1);
			d.setDate(d.getDate()-1);
			startStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-1";
			endStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}else if(type=="TODAY"){
			startStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
			endStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}else if(type=="YESTERDAY"){
			d.setDate(d.getDate()-1);
			startStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
			endStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}
		document.getElementById("start_date").value=startStr;
		document.getElementById("end_date").value=endStr;
		doAutoCheck("cb_order_date");
	}
	function selectProduct(){
		var url="/base/ProductMainForSelect.ihtm";
		ShowIframe("选择材料",url,900,500,"selectProductCallBack()",1024,600);
	}
	function selectProductCallBack(){
		if(popRetVal!=null){
			document.getElementById("pro_id").value=popRetVal[0];
			document.getElementById("pro_name").value=popRetVal[2];
			doAutoCheck("cb_pro_name");
		}
	}
</script>
</head>
<body>
<div class="Wrap"><!-- 页面主框架 -->
    
	<div id="ListContainer" class="Container"><!-- 主体容器 -->
	    
	    <!-- 标题栏 -->
	    <div class="Heading BillIcon">
	        <div class="HeadingContent">
	            <h1>库存日志</h1>
	            <span class="Note">查看材料库存单价的日志</span>
	        </div>
	    </div>
	
		<!-- 主内容 -->
		<div class="Content">
	        <!-- 筛选控件栏 -->
	        <div class="FilterBar ClearFix">
	            <div class="SearchIcon"></div>
	            <span class="fl">
	            	<table class="MoreOption" cellpadding="0" cellspacing="0">
	            		<th class="c1" width="80px">
	            			<input type="checkbox" name="cb_order_date" id="cb_order_date" <c:if test="${cbOrderDate=='1' || searchType=='2'}">checked="true"</c:if> style="visibility:hidden;" />
	            			日期
	            		</th>
	            		<td width="360px">
	            			<input type="text" class="TextBox Datetime" maxlength="15" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_order_date');" id="start_date" name="start_date" value="<c:out value="${startDate}" />">
			            	<img src="/images/calendar.gif" class="imgIconButton" onClick="displayCalendar(document.getElementById('start_date'),'yyyy-mm-dd',this,false,'doAutoCheck(\'cb_order_date\')');">
			            	<input type="hidden" id="hid_start_date" value="<c:out value="${startDate}" />">
			            	至
			            	<input type="text" class="TextBox Datetime" maxlength="15" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_order_date');" id="end_date" name="end_date" value="<c:out value="${endDate}" />">
			            	<img src="/images/calendar.gif" class="imgIconButton" onClick="displayCalendar(document.getElementById('end_date'),'yyyy-mm-dd',this,false,'doAutoCheck(\'cb_order_date\')');">
			            	<input type="hidden" id="hid_end_date" value="<c:out value="${endDate}" />">
			            	<a href="javascript:setDate('CURRENT_MONTH');">本月</a>
							<a href="javascript:setDate('TODAY');">今天</a>
							<a href="javascript:setDate('YESTERDAY');">昨天</a>
							<a href="javascript:setDate('PREVIEW_MONTH');">上月</a>
	            		</td>
	            	</table>
	            </span>
	            <span class="fr">
	            	<a href="javascript:;" id="lnkMoreOption">更多查询选项</a>
		  			<input type="button" value=" 查 询" onClick="doSearch();" class="buttom search-but" id="sSearchButton" name="sSearchButton">
	            </span>
				<div id="dvMoreOptionBox" class="MoreOptionBox" style="display:none;">
					<table class="MoreOption" cellpadding="0" cellspacing="0">
						<tr>
							<th class="c1" width="80px">
			        			<input type="checkbox" checked="true" disabled="true">
			        			仓库
			        		</th>
			        		<td class="c1" width="280px">
			        			<select name="sto_id" id="sto_id">
					  				<option value="0">==请选择==</option>
					  				<c:forEach var="item" items="${storehouseList}">
					  				<c:if test="${item.enabled=='Y' || stoId==item.id}"><option value="${item.id}" <c:if test="${stoId==item.id}">selected</c:if>>${item.stoName}</option></c:if>
					  				</c:forEach>
				  				</select>
			    			</td>
			    		</tr>
						<tr>
							<th class="c1">
			        			<input type="checkbox" name="cb_pro_name" id="cb_pro_name" <c:if test="${cbProName=='1'}">checked="true"</c:if>>
			        			品名规格
			        		</th>
			        		<td class="c1">
			        			<input type="text" class="TextBox readonly" readonly="readonly" maxlength="15" name="pro_name" id="pro_name" value="<c:out value="${proName}" />" >
								<img class="imgIconButton" src="/images/make-a.gif" onClick="selectProduct();" />
								<input type="hidden" id="pro_id" name="pro_id" value="${proId}">
								<input type="hidden" id="hid_pro_name" value="<c:out value="${proName}" />">
			    			</td>
			    		</tr>
						<tr>
							<th class="c1">
			        			<input type="checkbox" name="cb_pro_code" id="cb_pro_code" <c:if test="${cbProCode=='1'}">checked="true"</c:if>>
			        			材料编号
			        		</th>
			        		<td class="c1">
			        			<input type="text" class="TextBox" maxlength="15" name="pro_code" id="pro_code" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_pro_code');" value="<c:out value="${proCode}" />" >
								<input type="hidden" id="hid_pro_code" value="<c:out value="${proCode}" />">
			    			</td>
			    		</tr>
					</table>
					
					<div class="OptionOrderBy">
	                    <span class="fr"><a href="javascript:;" id="lnkHiddenOption">隐藏查询选项</a></span>
	                </div>
				</div>
			</div>
			
			<div id="contentDiv" style="background:#eafaff;">

			      <div class="table-list">
			        <table width="100%">
			          <tr>
							<th width="10%" rowSpan="2">单号</th>
							<th width="8%" rowSpan="2">记账日期</th>
							<th width="7%" rowSpan="2">供需方</th>
							<th width="4%" rowSpan="2">类型</th>
							<th width="8%" rowSpan="2">备注</th>
							<th width="7%" rowSpan="2">材料编号</th>
							<th width="7%" rowSpan="2">品名规格</th>
							<th width="4%" rowSpan="2">单位</th>
							<th width="15%" colSpan="3" align="center">入库</th>
							<th width="15%" colSpan="3" align="center">出库</td>
							<th width="15%" colSpan="3" align="center">结存</th>
						</tr>
						<tr>
							<th width="5%">数量</th>
							<th width="5%">单价</th>
							<th width="5%">金额</th>
							<th width="5%">数量</th>
							<th width="5%">单价</th>
							<th width="5%">金额</th>
							<th width="5%">数量</th>
							<th width="5%">单价</th>
							<th width="5%">金额</th>
						</tr>
						<c:if test="${fn:length(list)==0}">
						<tr>
							<td colspan="17">没有出入库数据</td>
						</tr>
						</c:if>
						<c:forEach var="item" items="${list}" varStatus="i">
						<c:if test="${(i.index mod 2)==0}"><c:set var="trClass" value="query_list_data_tr1" /></c:if>
						<c:if test="${(i.index mod 2)!=0}"><c:set var="trClass" value="query_list_data_tr2" /></c:if>
						<c:set var="defaultFontColor" value="#000000" />
						<c:if test="${item.operType=='UN_EXAM' || item.operType=='CANC' || item.operType=='UN_STOC'}"><c:set var="defaultFontColor" value="red" /></c:if>
						<tr class="${trClass}" index="${i.index+1}" style="color:${defaultFontColor}" defaultFontColor="${defaultFontColor}" onmouseout='javascript:mouseout(this)' onmouseover='javascript:mouseover(this)'>
							<td><a href="javascript:doShow(${item.billId},'${item.billType}');">${item.billCode}</a></td>
							<td><fmt:formatDate value="${item.ioTime}" pattern="yyyy-MM-dd HH:mm"/></td>
							<td>${item.otherName}</td>
							<td>
								<c:if test="${item.billType=='IN_BILL'}">入</c:if>
								<c:if test="${item.billType=='PURC_BILL'}">采购</c:if>
								<c:if test="${item.billType=='OUT_BILL'}">出</c:if>
								<c:if test="${item.billType=='ALLO_BILL' && item.ioType=='OUT'}">调出</c:if>
								<c:if test="${item.billType=='ALLO_BILL' && item.ioType=='IN'}">调入</c:if>
							</td>
							<td>${item.mark}</td>
							<td>${item.productCode}</td>
							<td>${item.productName}</td>
							<td>${item.productUnit}</td>
							<td><commonTag:parseBigDecimal source="${item.inAmount}" /></td>
							<td><c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';STOR_COST;')!=-1}"><commonTag:parseBigDecimal source="${item.inUnitPrice}" /></c:if></td>
							<td><c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';STOR_COST;')!=-1}"><commonTag:parseBigDecimal source="${item.inCost}" /></c:if></td>
							<td><commonTag:parseBigDecimal source="${item.outAmount}" /></td>
							<td><c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';STOR_COST;')!=-1}"><commonTag:parseBigDecimal source="${item.outUnitPrice}" /></c:if></td>
							<td><c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';STOR_COST;')!=-1}"><commonTag:parseBigDecimal source="${item.outCost}" /></c:if></td>
							<td><commonTag:parseBigDecimal source="${item.balAmount}" /></td>
							<td><c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';STOR_COST;')!=-1}"><commonTag:parseBigDecimal source="${item.balUnitPrice}" /></c:if></td>
							<td><c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';STOR_COST;')!=-1}"><commonTag:parseBigDecimal source="${item.balCost}" /></c:if></td>
						</tr>
						</c:forEach>
					</table>
      			</div>
      		</div>
      		
      		<div class="modal-buttom" id="waitDiv" style="display:none">
				<span style="color:white">请稍候...</span>
			</div>
      		
      	</div>
	</div>
</div>
</body>
</html>
<script type="text/javascript">
	function ChangeWindowSize( container, maxWidth ){
	    setTimeout( function(){
	        var w1 = document.documentElement.clientWidth-40;
	        if( w1>maxWidth ) w1 = maxWidth;
	        else if( w1<970 ) w1 = 960;
	        container.style.width = w1+'px';
	    }, 300 );
	}
	var IsAdvSearch = false;
	(function(){
		doInit();
	    var ListContainer = document.getElementById('ListContainer');
	    ChangeWindowSize( ListContainer, 2020 );    // 超过 1280 的最大 1260 ，不全部铺满
	
	    var lnkMoreOption   = document.getElementById('lnkMoreOption');
	    var lnkHiddenOption = document.getElementById('lnkHiddenOption');
	    lnkMoreOption.onclick = function(){
	    	IsAdvSearch = true;
	        document.getElementById('dvMoreOptionBox').style.display = 'block';
	        document.getElementById('cb_order_date').style.visibility = 'visible';
	        this.style.visibility = 'hidden';
	    };
	    lnkHiddenOption.onclick = function(){
	    	IsAdvSearch = false;
	        document.getElementById('dvMoreOptionBox').style.display = 'none';
	        document.getElementById('cb_order_date').style.visibility = 'hidden';
	        lnkMoreOption.style.visibility = 'visible';
	    };
	})();
</script>

